Dart BigInt operator -
Syntax & Examples


BigInt.operator - operator

The `operator -` in Dart performs subtraction between two BigInt objects.


Syntax of BigInt.operator -

The syntax of BigInt.operator - operator is:

operator -(BigInt other) → BigInt

This operator - operator of BigInt subtraction operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe BigInt object to subtract


✐ Examples

1 Subtract Positive BigInts

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with positive integers.
  2. We use the - operator to subtract num2 from num1.
  3. We print the result of the subtraction to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(10);
  BigInt num2 = BigInt.from(6);
  BigInt result = num1 - num2;
  print('Result of subtraction: $result');
}

Output

Result of subtraction: 4

2 Subtract Positive BigInts (larger number first)

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with positive integers.
  2. We use the - operator to subtract num2 from num1.
  3. We print the result of the subtraction to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(100);
  BigInt num2 = BigInt.from(50);
  BigInt result = num1 - num2;
  print('Result of subtraction: $result');
}

Output

Result of subtraction: 50

3 Subtract Positive BigInts (negative result)

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with positive integers.
  2. We use the - operator to subtract num2 from num1.
  3. We print the result of the subtraction to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(5);
  BigInt num2 = BigInt.from(10);
  BigInt result = num1 - num2;
  print('Result of subtraction: $result');
}

Output

Result of subtraction: -5

Summary

In this Dart tutorial, we learned about operator - operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.